import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'
import axios from 'axios'

import Wui from 'wui-mobile'
import '../src/assets/js/rem'

import 'wui-mobile/dist/wui.css'
import WxSdk from '../src/fetch/wxsdk'



window.Wui = Wui;
window.WxSdk = WxSdk;
Vue.config.productionTip = false;
Vue.use(Wui);
Vue.use(WxSdk);

/*
 * @synopsis 将axios绑定到Vue对象的原型链上
 * @param {String} url 地址
 * @param {Object} params 参数
 * @param {Function} callback 回调函数
 * @param {String} method 请求方式
 * */
Vue.prototype.$http = function(url, params, callback, method = 'post') {
    if (typeof callback !== 'function') {
        return;
    }
    let config = {};
    config['method'] = method;

    config['url'] = url;
    if (method == 'post') {
        config['data'] = params;
    } else if (method == 'get') {
        config['params'] = params;
    }
    axios(config)
        .then((res) => {
            callback(res.data)
        })
        .catch((error) => {
            callback(error)
        });
}

router.beforeEach((to, from, next) => {
    window.scrollTo(0,0);
    next();
});

new Vue({
    el: '#app',
    router,
    store,
    components: { App },
    template: '<App/>'
})